package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.dto.GoodsSalesDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.entity.Orders;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.scheduling.annotation.Scheduled;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

@Mapper
public interface OrderMapper {
    /**
     * 插入订单数据
     * @param orders
     */
    void insert(Orders orders);

    /**
     * 根据状态和下单时间查询订单
     * @param Status
     * @param OrderTime
     * @return
     */
    @Select("select * from orders where status=#{Status} and order_time<#{OrderTime}")//下单时间比当前时间早15分钟的都已经是超时的订单
    List<Orders> getByStatusAndOrderTime(Integer Status, LocalDateTime OrderTime);

    /**
     * 更新订单状态
     * @param order
     */
    void update(Orders order);

    /**
     * 分页查询订单
     * @param ordersPageQueryDTO
     * @return
     */
    Page<Orders> pageQuery(OrdersPageQueryDTO ordersPageQueryDTO);

    /**
     * 根据id查询订单详细
     * @param id
     * @return
     */
    @Select("select * from orders where id=#{id}")
    Orders getById(Long id);

    /**
     * 根据状态统计订单数量
     * @param status
     */
    @Select("select count(id) from orders where status = #{status}")
    Integer countStatus(Integer status);

    /**
     * 根据订单号查询订单
     * @param outTradeNo
     * @return
     */
    @Select("select * from orders where number=#{outTradeNo}")
    Orders getByNumber(String outTradeNo);

    /**
     * 根据状态和下单时间查询订单总金额
     * @param beginTime
     * @param endTime
     * @param status
     * @return
     */
    @Select("select sum(amount) from orders where status = #{status} and order_time between #{beginTime} and #{endTime}")
    Double sumAmountByStatusAndLocalTime(LocalDateTime beginTime, LocalDateTime endTime, int status);

    /**
     * 根据状态和下单时间查询订单数量
     * @param map
     * @return
     */
    Integer countByMap(Map map);

    /**
     * 统计指定时间区间内的菜品销量Top10
     * @param beginTime
     * @param endTime
     * @return
     */
    List<GoodsSalesDTO> getSalesTop10(LocalDateTime beginTime, LocalDateTime endTime);
}
